<?php/*  PHP version 5  Copyright (c) 2002-2019ECISP.CN、EarcLink.COM  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220*/


use application\ESPCMS_AdminAuthority;
use admin_application\AdminPublicDB;
use admin_application\link\MenuLink;

class lib_menu {

	public static function call_menu($parameter, $filename = 'lib_menu', $outHTML = null) {

		global $espcms_link_db, $espcms_command, $module_array;
		$espcms_admin_templates = espcms_admin_template();
		$espcms_admin_templates->libfile = true;

		$menu_url_key = espcms_get_app('requetst');
		$menu_url_key_array = explode('/', $menu_url_key);

		$db_table = ESPCMS_DB_PREFIX . "menulink";
		$db_sql = "SELECT * FROM $db_table WHERE menu_upid=0 AND menu_isshow=1 AND menu_isclass=1 ORDER BY menu_pid,menu_id";
		$db_query = $espcms_link_db->db_query($db_sql);
		while ($fetch_row = $espcms_link_db->db_array_list($db_query)) {

			if (!ESPCMS_AdminAuthority::authorityVerify($fetch_row['menu_dirname'])) {
				continue;
			}

			$menu_array_nov = array();

			$fetch_row['open'] = $menu_url_key_array['0'] == $fetch_row['menu_dirname'] && !empty($fetch_row['menu_dirname']) ? 'open' : null;


			$db_sql_nov = "SELECT * FROM $db_table WHERE menu_dirname='" . $fetch_row['menu_dirname'] . "' AND menu_isshow=1 AND menu_isclass=1 ORDER BY menu_pid,menu_id";
			$db_query_nov = $espcms_link_db->db_query($db_sql_nov);
			while ($fetch_row_nov = $espcms_link_db->db_array_list($db_query_nov)) {

				if (!ESPCMS_AdminAuthority::authorityVerify($fetch_row_nov['menu_module'])) {
					continue;
				}
				$fetch_row_nov['open'] = $menu_url_key_array[0] == $fetch_row_nov['menu_dirname'] && $fetch_row_nov['menu_classname'] == $menu_url_key_array[1] ? 'open' : null;

				$fetch_row_nov['link'] = MenuLink::getLink('menu', $fetch_row_nov);
				$menu_array_nov[] = $fetch_row_nov;
			}
			$fetch_row['nov'] = $menu_array_nov;
			$menu_array[] = $fetch_row;
		}

		$lng = AdminPublicDB::get_lancode();
		$lan_array = AdminPublicDB::get_lan_list($lng, false, false, true);
		if (is_array($lan_array)) {
			foreach ($lan_array as $key => $value) {
				$value['app'] = $menu_url_key;
				$lan_array[$key]['link'] = MenuLink::getLink('lng', $value);
			}
		}
		$espcms_admin_templates->into('lan_array', $lan_array);
		$espcms_admin_templates->into('menu_array', $menu_array);
		$espcms_admin_templates->into('module_array', $module_array);
		if (!empty($outHTML)) {
			$output = $espcms_admin_templates->fetch(null, null, $outHTML);
		} else {
			$output = $espcms_admin_templates->fetch('public/' . $filename);
		}
		return $output;
	}

}
